home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: miker3@ix.netcom.com (Mike Rubenstein)
- Newsgroups: comp.lang.c
- Subject: Re: Please help ?!
- Date: Sun, 28 Jan 1996 22:54:04 GMT
- Organization: Netcom
- Message-ID: <310bfdbc.170966400@nntp.ix.netcom.com>
- References: <4dm889$3hs@neptunus.pi.net> <4drnv1$cr@news.iag.net> <4drq5i$cr@news.iag.net> <4e6hse$dvl@ns.RezoNet.NET> <310a2389.49571776@nntp.ix.netcom.com> <4eg6h8$1db5@info.estec.esa.nl>
- NNTP-Posting-Host: ix-dc16-21.ix.netcom.com
- X-NETCOM-Date: Sun Jan 28 2:53:38 PM PST 1996
- X-Newsreader: Forte Agent .99c/16.141
-
- 328pt@SPOD2.dev.esoc.esa.de (Phil Tregoning) wrote:
-
- > >> In referenced article, John R Buchan says...
- > >>
- > >> >> cpy = (char *) malloc(MAXLEN);
- > >> >
- > >> >The cast is unnecessary and can hide errors. You should remove it.
- > >
- > >ray@ultimate-tech.com (Ray Dunn) wrote:
- > >
- > >> [...] adding a cast to a pointer of the same
- > >> type to the malloc return is the *safest* thing you can do:
- > >>
- > >> fred = malloc(n * sizeof(int));
- > >>
- > >> Oops - fred isn't an "int *" it's a "long *", but the compiler wont
- > >> issue any warnings, but in:
- > >>
- > >> fred = (int *)malloc(n * sizeof(int));
- > >>
- > >> the compiler will issue an error.
- >
- > miker3@ix.netcom.com (Mike Rubenstein) replied :
- >
- > >Why will the compiler issue an error in that case? It's completely
- > >legal code.
- >
- > From K&R2 section 5.4 :
- >
- > "It is not legal to [stuff about illegal pointer arithmatic], or even,
- > except for void *, to assign a pointer of one type to a pointer of
- > another type without a cast."
- >
- > If you assign a int * to a long * the compiler can certainly pick that up.
-
- Whoops. You are correct. In the famous words of Emily Latella,
- "never mind."
-
-
- Michael M Rubenstein
-